package cool.mtc.base.plugin.generator.code.model.template.ui;

import cool.mtc.base.plugin.generator.code.model.template.BaseTemplateParam;
import cool.mtc.core.util.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author 明河
 */
@Data
@EqualsAndHashCode(callSuper = true)
public abstract class BaseUiTemplateParam extends BaseTemplateParam {

    /**
     * 名称
     * 用于页头及编辑对话框显示标题
     */
    private String name = StringUtil.EMPTY;

    /**
     * 请求的相对url
     * 例：Controller类注解中的url
     */
    private String requestRelativeUrl;

    @Override
    public String getTargetFilePath() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.fixPath(this.getProjectPath()));
        if (StringUtil.isNotEmpty(this.getBaseRelativePath())) {
            sb.append(this.fixPath(this.getBaseRelativePath()));
        }
        if (StringUtil.isNotEmpty(this.getRelativePath())) {
            sb.append(this.fixPath(this.getRelativePath()));
        }
        sb.append(this.getFileName());
        return sb.toString();
    }

    public abstract String getBaseRelativePath();

    public abstract String getFileName();

    @Override
    public void handleCheckParamsCorrect() {
        super.handleCheckParamsCorrect();
        if (StringUtil.isEmpty(this.getClassPrefix())) {
            throw new RuntimeException(this.handleMessage("未设置[classPrefix]"));
        }
        if (StringUtil.isEmpty(this.getRequestRelativeUrl())) {
            throw new RuntimeException(this.handleMessage("未设置[requestRelativeUrl]"));
        }
    }
}
